import 'package:demo/utils/sp_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

import '../../../net/api_provider.dart';
import '../../widgets/CommonDialog.dart';

class FeedbackController extends GetxController {

  var contentStr = '';
  var phoneStr = '';
  final TextEditingController textController = TextEditingController();

  @override
  void onInit() {
    super.onInit();
    textController.text = SpUtil.read(SpUtil.PHONE, '');
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  @override
  void dispose() {
    super.dispose();
    textController.dispose();
  }

  ApiProvider apiProvider = Get.find();
  void submit() async {
    if (contentStr.isEmpty){
      EasyLoading.showToast('请留下您的建议吧');
      return;
    }

    var result = await apiProvider.getData({'content': contentStr}, ApiProvider.feedback);
    if (result.code == 200) {
      Get.dialog(
        CommonDialog(
          hintNo: true,
          canCancel: false,
          contentStr:'您已提交成功，请保持电话畅通！',
          yesFun: ()=> Get.back()
        ),
      );
    }else{
      EasyLoading.showToast('${result.msg}');
    }
  }
}
